<template>
	<view class="">
			
		<view class="nav-back">
			<top-heigth backTitle="所属商家"></top-heigth>
		</view>
		<view class="content-box m-t24" v-if="!supplierInfo">
			<view class="content-box">
				<uv-input placeholder="请输入商家邀请码" type="number" border="bottom" v-model="value"></uv-input>
				<view class="login-but2" @click="joinTeam">立即加入</view> 
			</view>
		</view>
		<view class="content-box m-t24" v-else>
			<view class="content-box">
				 <uv-input :value="supplierInfo.supplierName" border="bottom"></uv-input>
			</view>
		</view>
	</view>
</template>

<script>
	import TopHeigth from '@/components/TopHeigth.vue'
	
	export default {
		data() {
			return {
				value: '',
				supplierId: null,
				id: null,
				version: null,
				supplierInfo: null
			}
		},
		components: { TopHeigth },
		onLoad(e) {
			this.id = e.id
			this.supplierId = e.supplierId
			this.version = e.version
			if(this.supplierId > 0){
				// 请求商家信息
				uni.$u.http.post('/api/shop/v1_0/tAppSupplierRCA/turnTAppSupplierInfo',{
					id: this.supplierId
				}).then((res) => {
					this.supplierInfo = res.data
				})
			}
		},
		mounted() {
			
		},
		methods: {
			joinTeam(){
				uni.$u.http.post('/api/shop/v1_0/tAppSupplierRCA/turnTAppSupplierInfo',{
					id: this.value
				}).then((res) => {
					if(res.code == 200){
						uni.$u.http.post('/api/shop/v1_0/tAppStaffRCA/updateTAppStaff',{
							id: this.id,
							version: this.version,
							supplierId: this.value,
						}).then((res) => {
							uni.showToast({
								icon: "none",
								title: res.message
							})
							setTimeout(() => {
								uni.navigateBack()
							}, 1000)
						})
					}else{
						uni.showToast({
							icon: "none",
							title: "邀请码错误"
						})
					}
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	@mixin flex($direction: row) {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: $direction;
	}
	.uv-nav-slot {
		@include flex;
		align-items: center;
		justify-content: space-between;
		border-width: 0.5px;
		border-radius: 100px;
		border-color: #dadbde;
		padding: 3px 7px;
		opacity: 0.8;
	}
</style>
